package org.carabiner.examples;

import javax.swing.JLabel;
import javax.swing.event.ListDataEvent;

import org.jmock.Mock;
import org.jmock.MockObjectTestCase;

public class TestDataModelListener extends MockObjectTestCase
{
  private DataModelListener dataModelListener = null;

  private MyDataModel mockModel;

  private JLabel label;

  protected void setUp() throws Exception
  {
    super.setUp();
    Mock mock = new Mock(MyDataModel.class);
    mock.expects(once()).method("getStringData").will(returnValue("Foo"));
    mockModel = (MyDataModel) mock.proxy();
    label = new JLabel();
    dataModelListener = new DataModelListener(label);
  }

  protected void tearDown() throws Exception
  {
    dataModelListener = null;
    super.tearDown();
  }

  public void testContentsChanged()
  {
    assertEquals("", label.getText());
    dataModelListener.contentsChanged(new ListDataEvent(mockModel,
        ListDataEvent.CONTENTS_CHANGED, 0, 1));
    assertEquals("Foo", label.getText());
  }

  public void testIntervalAdded()
  {
    assertEquals("", label.getText());
    dataModelListener.intervalAdded(new ListDataEvent(mockModel,
        ListDataEvent.INTERVAL_ADDED, 0, 1));
    assertEquals("Foo", label.getText());
  }

  public void testIntervalRemoved()
  {
    assertEquals("", label.getText());
    dataModelListener.intervalRemoved(new ListDataEvent(mockModel,
        ListDataEvent.INTERVAL_REMOVED, 0, 1));
    assertEquals("Foo", label.getText());
  }

}
